<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>合集列表</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<button class="layui-btn" href="{:url('/video/addGatherPage')}" id="addGather">添加合集</button>

<div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" onsubmit="return false">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 7%">视频名称</label>
            <div class="layui-input-block">
                <input type="text" name="username"  placeholder="请输入视频名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 7%">视频类型</label>
            <div class="layui-input-block">
                <select id="types" lay-verify="required">
                    <option value="">请选择</option>
                    {foreach $cat as $val}
                    <option value="{$val.id}">{$val.cat_name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <button class="layui-btn"  id="search"><i class="layui-icon">&#xe615;搜索</i></button>
    </form>
</div>

<table id="adminList">

</table>
</body>
</html>
<script>
    layui.use('layer',function(){
        layer = layui.layer;
    });
</script>
<script>
    //添加合集
    $("#addGather").click(function (){
        window.location.href ="{:url('/video/addGatherPage')}";
    })
    //表格
    $('#adminList').bootstrapTable({
        //获取行号
        language: 'zh-CN',
        autoclose: true,
        todayHighlight: true,
        striped: true,//设置为 true 会有隔行变色效果
        method: 'post',//服务器数据的请求方式 'get' or 'post'
        url: "{:url('/video/examVideo')}",//服务器数据的加载地址
        toolbar:'#toolbar',//
        searchOnEnterKey:true,
        sortName:'ID',//排序字段
        sortOrder : 'desc',//降序
        sidePagination: "server",   //分页方式：client客户端分页，server服务端分页（*）
        pagination: 'false',//设置为 true 会在表格底部显示分页条
        clickToSelect:'true',//设置true 将在点击行时，自动选择rediobox 和 checkbox
        singleSelect:'true',//设置True 将禁止多选
        pageSize: '15',//如果设置了分页，页面数据条数
        pageList:[15,30,50],
        smartDisplay:false,
        //得到查询的参数
        queryParams : function (params){
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                rows: params.limit,                         //页面大小
                page: (params.offset / params.limit) + 1,   //页码
                sort: params.sort,      //排序列名
                sortOrder: params.order,//排位命令（desc，asc）
                searchName:$("input[name=username]").val(),
                searchType:$("#types").val(),
                type:$("#type").val()
            };
            return temp;
        },
        columns: [
            {field: 'id', title: 'ID', align:'center'},
            {field: 'title', title: '视频名称', align:'center'},
            {formatter:teacher, title: '指导教师', align:'center'},
            {align:'center', title:'操作', formatter:operateFormatter}
        ]
    })
    function teacher(val,rows){
        if(rows.get_table_teacher){
            return rows.get_table_teacher.title;
        }
    }
    //选择操作
    function operateFormatter(val,rows)
    {
        return [
            "<button type='button' onclick='section("+rows.id+")' class='btn btn-primary btn-xs'>章节管理</button>&nbsp;&nbsp;",
            "<button type='button' onclick='video("+rows.id+")' class='btn btn-info btn-xs'>合集管理</button>&nbsp;&nbsp;",
            "<button type='button' onclick='d("+rows.id+")' class='btn btn-danger btn-xs'>删除集合</button>"
        ].join('');
    }
    //检索
    $("#search").click(function(){
        $("#adminList").bootstrapTable(('refresh'));
    })

    //章节管理
    function section(id){
        window.location.href ='{:url("/video/section")}?id='+id;
    }
    //合集管理
    function video(id) {
        window.location.href ='{:url("/video/gather")}?id='+id;
    }
    //删除合集
    function d(id) {
        layer.confirm('确认删除此集合？', {
            btn: ['是的','不'] //按钮
        }, function(){
            $.ajax({
                url:"{:url('/video/delGather')}",
                data:{id:id},
                type:"post",
                dataType:"json",
                beforeSend:function () {
                    index = layer.load(2, {time: 100*1000});
                },
                success:function(res){
                    if(res.code){
                        layer.close(index);
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }

            })
        })
    }
</script>